package qz_rpt
import java.text.SimpleDateFormat
class FinalTrendPassYieldByMonthController {


    def commonSqlService
    def dynamicQueryService

    def index(Integer max) {
        def cellList = org.kdx.DataUtils.getCellList()
        def pageSizeList = org.kdx.DataUtils.getPageSizeList()

        [totalCount: 5, pageSize: 20, pageCurrent: 1, orderField: 'id', orderDirection: 'asc', pageSizeList: pageSizeList, cellList: cellList]
    }

    def finalTrendPassYieldByMonth(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = ((pageCurrent - 1) * pageSize) + 1
        params.endno = pageCurrent * pageSize
        def finalTrendPassYieldByMonth=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0
        def tableHeadList = []
        def finalTrendPassYieldByMonthPic=[]
         SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM')
         def startTime = params.startTime ? sdf.parse(params.startTime) : sdf.parse(sdf.format(new Date().clearTime()))
         def endTime = params.endTime ? sdf.parse(params.endTime) : sdf.parse(sdf.format(new Date()))
         params.startTime = sdf.format(startTime)
         params.endTime = sdf.format(endTime)
//        def customerLotIdList = commonSqlService.customerLotIdList(params)
        params.SYS_QUERY_NAME = 'checkStepList'
        def checkStepList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'partDirect'
        def partDirect = dynamicQueryService.queryForList(params)
        if(params.EXPORT_CONTENT_NAME=='Excel'){
            params.SYS_QUERY_NAME = 'finalTrendPassYieldByMonth'
            finalTrendPassYieldByMonth = dynamicQueryService.queryForList(params)

            if (finalTrendPassYieldByMonth.size() > 0) {
                tableHeadList = finalTrendPassYieldByMonth[0].keySet()
            }

            params.SYS_QUERY_NAME = 'finalTrendPassYieldByMonthPic'
            finalTrendPassYieldByMonthPic = dynamicQueryService.queryForList(params)

            /*params.SYS_QUERY_NAME = 'oncePassYieldByMonthCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT*/
        }

        println(params.stepDesc)

        [pageSize  : pageSize, pageSizeList: pageSizeList, startno: params.startno ?: '', endno: params.endno ?: '',checkStepList:checkStepList,partDirect:partDirect,
         totalCount: totalCount, tableHeadList: tableHeadList,
//         customerLotIdList:customerLotIdList,
         customerLotId:params.customerLotId?:'',
         group4: params.group4 ?: '', grade2: params.grade2 ?: '',partType:params.partType?:'',stepDesc:params.stepDesc?:'',
         startTime:params.startTime?:'',endTime:params.endTime?:'',
         finalTrendPassYieldByMonth:finalTrendPassYieldByMonth,finalTrendPassYieldByMonthPic:finalTrendPassYieldByMonthPic,
         group3:params.group3,customerDirect:params.customerDirect?:'']

    }
}
